/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.yutel.wuzi.entities;

import javax.microedition.lcdui.Graphics;

/**
 *
 * @author yuanyajun
 */
public class Chess {
    private boolean black;
    private int x;
    private int y;

    public Chess(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public void draw(Graphics g,int dx, int dy, int size) {
        if (black) {
            g.setColor(0, 0, 0);
        } else {
            g.setColor(255, 255, 255);
        }
        g.fillArc(x * dx + dx - size, y * dy + dy - size, 2 * size, 2 * size, 0, 360);
    }
    
    public void drawCurrent(Graphics g,int dx, int dy, int size) {
        g.setColor(0, 255, 0);
        g.drawArc(x * dx + dx - size, y * dy + dy - size, 2 * size, 2 * size, 0, 360);
    }

    public void setBlack(boolean black) {
        this.black = black;
    }

    public boolean equals(Object obj) {
        if (!(obj instanceof Chess)) {
            return false;
        }
        Chess p = (Chess) obj;
        return p.x == x && p.y == y;
    }

    public String toString() {
        return IntToChar(x)+(y+1);
    }

    public String IntToChar(int i) {
        switch (i) {
            case 0:return "a";
            case 1:return "b";
            case 2:return "c";
            case 3:return "d";
            case 4:return "e";
            case 5:return "f";
            case 6:return "g";
            case 7:return "h";
            case 8:return "i";
            case 9:return "j";
            case 10:return "k";
            case 11:return "l";
            case 12:return "m";
            case 13:return "n";
            case 14:return "o";
            default:return "x";
        }
    }
    public int CharToInt(char c) {
        switch (c) {
            case 48:return 0;
            case 49:return 1;
            case 50:return 2;
            case 51:return 3;
            case 52:return 4;
            case 53:return 5;
            case 54:return 6;
            case 55:return 7;
            case 56:return 8;
            case 57:return 9;
            case 97:return 10;
            case 98:return 11;
            case 99:return 12;
            case 100:return 13;
            case 101:return 14;
            case 102:return 15;
            default:return -1;
        }
    }

    public void setX(int x) {
        this.x = x;
    }

    public void setY(int y) {
        this.y = y;
    }

    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }

    public boolean isBlack() {
        return black;
    }
    
}
